package com.lw.kotlin_mvvm_master.view.user

import android.os.Bundle
import androidx.activity.viewModels
import com.lw.common.base.BaseActivity
import com.lw.common.network.request.requestApi
import com.lw.kotlin_mvvm_master.databinding.ActivityUserInfoBinding

class UserInfoActivity : BaseActivity<ActivityUserInfoBinding>() {
    private val mViewModel by viewModels<UserViewModel>()
    override fun initView(savedInstanceState: Bundle?) {

    }

    override fun initData() {
        super.initData()
        mBinding.stateView.showLoading()
        requestApi({
            mViewModel.geUserInfo("zhixingren1", "123456")
        }, toast = true) {
            onSuccess = {
                mBinding.stateView.showContent()
                mBinding.text.text = it?.roleName
            }
            onFailed = { _, msg ->
                mBinding.stateView.showError(msg)
            }
            onError = { e ->
                mBinding.stateView.showError(e.message)
            }
        }
    }
}